package com.lian.hope.mapper;

import com.lian.hope.model.dto.ProjectsDTO;
import com.lian.hope.model.po.Projects;
import com.lian.hope.model.vo.ProjectsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProjectsMapper {
    /**
     * 分页获取项目列表
     *
     * @return
     */
    @Select("select * from projects")
    List<ProjectsVO> listProjects();

    /**
     * 新增项目
     *
     * @param projects
     */
    @Select(
        "insert into projects(project_name, brief, implementation_plan, project_desc_html, create_time,  " +
        "target_amount,img_url,user_id) " +
        "VALUES (#{projectName}, #{brief}, #{implementationPlan}, #{projectDescHtml},  #{createTime}, " +
        "#{targetAmount}," +
        "#{imgUrl},#{userId})")
    void insertProjects(Projects projects);

    @Select(
        "SELECT * FROM projects WHERE id = (SELECT id FROM (SELECT id FROM projects ORDER BY RAND() LIMIT 1) AS sub)")
    ProjectsVO getRandomProjects();

    /**
     * 根据项目id集合获取所有项目
     *
     * @param ids
     * @return
     */
    List<ProjectsVO> listProjectsByIds(List<Long> ids);

    @Select("select * from projects where id = #{id}")
    ProjectsVO getProjectById(Long id);
}
